﻿using Business.DB.Interface;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System.Reflection;

namespace 反射
{
    public class SimpleFactory
    {

        

        /// <summary>
        /// 封装
        /// 反射返回一个IDBhelper的实例
        /// </summary>
        /// <returns></returns>
        public static IDBHelper CreateInstance()
        {
            Assembly assembly1 = Assembly.LoadFrom("Business.DB.Sqlserver.dll");//当前执行目录下去读取dll文件
            Type type = assembly1.GetType("Business.DB.Sqlserver.SqlserverHelper");//使用命名空间全名称
            var oInstance = Activator.CreateInstance(type) as IDBHelper;
            return oInstance;
        }
    }

    public class AppConfig
    {
        public static string GetConfig(string key)
        {
            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
            IConfiguration configuration = builder.Build();
            string configValue = configuration.GetSection(key).Value;
            return configValue;
        }
    }
}